import { Msger } from "../Msger";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class EffectLayerSc extends cc.Component {
    // LIFE-CYCLE CALLBACKS:

    @property(cc.Prefab)
    bao: cc.Prefab = null;
    @property(cc.Node)
    backEffectLayer: cc.Node = null;
    onLoad() {
        Msger.on(Msger.on_game_add_effect, this.on_game_add_effect, this);
    }

    // update (dt) {}

    private on_game_add_effect(e) {
        let layer = this.node;
        if (e.back) {
            layer = this.backEffectLayer;
        }
        if (e.key && !e.obj) {
            if (e.key == "bao") {
                e.obj = cc.instantiate(this.bao);
                e.obj.x = e.x;
                e.obj.y = e.y;
                if (e.color) {
                    e.obj.color = e.color;
                }
                if(e.radius){
                    e.obj.scale = e.radius / 100 + 0.3;
                }
            }
        }
        layer.addChild(e.obj);
    }
}
